package com.zlt.appparking.controller;

import com.zlt.appparking.service.BalanceService;
import com.zlt.appparking.vo.Result;
import javafx.geometry.Pos;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

@RestController
@RequestMapping("balance")
public class BalanceController {

    @Autowired
    private BalanceService balanceService;

    /**
     * 查询钱包余额
     * @return
     */
    @PostMapping("balance")
    public Result balance(){
        try{
            BigDecimal balance = balanceService.selectBalance();
            return Result.ok("查询成功",balance);
        } catch (RuntimeException e){
            return Result.error(e.getMessage());
        }
    }

    /**
     * 充值余额
     * @param money
     * @return
     */
    @PostMapping("charge")
    public Result charge(String money){

        BigDecimal bd = new BigDecimal(money);//将数据转换成bigdecimal类型
        String success = balanceService.addCharge(bd);
        return Result.ok("订单已生成",success);
    }


    /**
     * 提现余额
     * @return
     */
    @PostMapping("withdrawalCharge")
    public Result withdrawalCharge(String money){
        BigDecimal bd = new BigDecimal(money);//将数据转换成bigdecimal类型
        String success = balanceService.withdrawalCharge(bd);
        return Result.ok("订单已生成",success);
    }




}
